import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import Components from 'unplugin-vue-components/vite'
import UnoCSS from 'unocss/vite'
import alias from '@rollup/plugin-alias'
const NutUIResolver = () => {
    return (name) => {
        if (name.startsWith('Nut')) {
            const partialName = name.slice(3)
            return {
                name: partialName,
                from: '@nutui/nutui',
                sideEffects: `@nutui/nutui/dist/packages/${partialName.toLowerCase()}/style`
            }
        }
    }
}
// https://vitejs.dev/config/
export default defineConfig({
    base: process.env.NODE_ENV === 'production' ? '/' : '',
    envDir: 'envDir',
    build: {
        sourcemap: process.env.NODE_ENV !== 'production',
        rollupOptions: {
            output: { dir: 'dist' }
        }
    },
    css: {
        preprocessorOptions: {
            scss: {
                additionalData: '@import "@nutui/nutui/dist/styles/variables.scss";',
                quietDeps: true
            }
        }
    },
    plugins: [
        vue(),
        UnoCSS(),
        Components({
            resolvers: [NutUIResolver()]
        }),
        alias({
            entries: [
                { find: '@', replacement: '/src' },
                { find: '@tools', replacement: '/src/tools/index.ts' },
                { find: '@http', replacement: '/src/http/sever.ts' },
                { find: '@pages', replacement: '/src/pages' }
            ]
        })
    ]
})
